package MyThread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class MyThread implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        int sum=0;
        for(int i=0;i<10;i++){
            sum+=i;
        }
        System.out.println(Thread.currentThread().getName()+":"+sum);
        return sum;
    }
}
class Test{
    public static void main(String[] args) {
        MyThread myThread = new MyThread();
        FutureTask<Integer> integerFutureTask = new FutureTask<>(myThread);
        new Thread(integerFutureTask,"t1").start();
        try {
            Integer integer = integerFutureTask.get();
            System.out.println(Thread.currentThread().getName()+":"+integer);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }
}